import {
    Entity,
    Column,
    PrimaryGeneratedColumn,
    Tree,
    TreeChildren,
    TreeParent
} from 'typeorm';

// tree结构
// materialized-path       1. 1.2 1.2.1表示树关系的
// closure-table  用的多，closure-table会新建一个 _closure表
@Entity()
@Tree('closure-table')
export class Category {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({ length: 50 })
    name: string;

    // 表示儿子
    @TreeChildren()
    children: Category[];

    // 表示父亲
    @TreeParent()
    parent: Category;
}
